package com.qsmx.qingqiuticket.app;

import androidx.multidex.MultiDexApplication;

import com.qsmx.core.app.Atmos;
import com.qsmx.core.fusion.FusionCode;
import com.qsmx.core.net.HttpUrl;
import com.qsmx.core.util.storage.AtmosPreference;
import com.qsmx.qingqiuticket.app.fusion.FusionPre;
import com.qsmx.qingqiuticket.app.util.OpenUDID;
import com.umeng.commonsdk.UMConfigure;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class TicketApp extends MultiDexApplication {

    @Override
    public void onCreate() {
        super.onCreate();
        Atmos.init(this)
                .withApiHost(HttpUrl.API_HOST)
                .withTestApiHost(HttpUrl.API_TEST_HOST)
                .withJavascriptInterface("android")
                .withWebHost("https://www.baidu.com/")
                .withInterceptor(new Interceptor() {
                    @Override
                    public Response intercept(Chain chain) throws IOException {

                        Request request = chain.request()
                                .newBuilder()
                                .removeHeader("User-Agent")
                                .addHeader("User-Agent", "QingQiuTicketApp/Android " + AtmosPreference.getCustomStringPre(FusionPre.STORE_NUM) + "-" + AtmosPreference.getCustomStringPre(FusionPre.MACHINE_NUM))
                                .build();
                        return chain.proceed(request);
                    }
                })
                .configure();
        OpenUDID.syncContext(this);

//        UMConfigure.preInit(getApplicationContext(), FusionCode.UM_APPKEY, "QINGQIU");
//        UMConfigure.init(this, FusionCode.UM_APPKEY, "QINGQIU", UMConfigure.DEVICE_TYPE_PHONE, null);

    }
}
